package com.lu.controller;

import com.lu.entity.Dormitory;
import com.lu.entity.Student;
import com.lu.service.dormitory.DormitoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class DormitoryController {
    @Autowired
    private DormitoryService dormitoryService;

    //查询所有宿舍信息
    @GetMapping("/dormitory")
    public List<Dormitory> getDormitory() {
        return dormitoryService.getDormitory();
    }

    //添加宿舍数据
    @PostMapping("/insertDormitoryData")
    void insertDormitoryData(@RequestBody Dormitory dormitory) {
        dormitoryService.addDormitory(dormitory);
    }

    //根据id查询宿舍数据
    @GetMapping("/findDormitoryById")
    public List<Dormitory> findDormitoryById(@RequestParam Integer id) {
        return dormitoryService.findDormitoryById(id);
    }

    //修改宿舍数据
    @PutMapping("/updateDormitory")
    public void updateDormitory(@RequestBody Dormitory dormitory) {
        dormitoryService.updateDormitory(dormitory);
    }

    //根据id删除宿舍数据
    @DeleteMapping("/deleteDormitory/{id}")
    public void deleteStudent(@PathVariable Integer id) {
        dormitoryService.deleteDormitory(id);
    }

    //根据传入的寝室号和宿舍楼查询对应的数据
    @PostMapping("/findDormitoryByName")
    public List<Dormitory> findDormitoryByName(@RequestBody Dormitory dormitory) {
        return dormitoryService.findDormitoryByName(dormitory);
    }
}
